﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BaseData;
using BaseData.Common;

namespace TaxData.Tax
{
    /// <summary>
    /// 税款相关配置
    /// </summary>
    public class TaxConfigData
    {
        /// <summary>
        /// 获取汇款计算方式
        /// </summary>
        /// <returns>应税计算根据：0，房产计税面积；1，租金收入</returns>
        public static int GetComputeType()
        {
            int type = 0;
            string sql = "select top 1 ComputeType from TaxConfig with(nolock)";
            object o = DataConfig.GetSingle(BusinessType.DBRead, sql);
            if (o != null && o != DBNull.Value)
            {
                int.TryParse(o.ToString(), out type);
            }
            return type;
        }

        /// <summary>
        /// 更新税款计算方式
        /// </summary>
        /// <param name="type">应税计算根据：0，房产计税面积；1，租金收入</param>
        /// <param name="optUserID">操作人ID</param>
        /// <returns>更新结果</returns>
        public static bool UpdateComputeType(int type, long optUserID)
        {
            string sql = "update TaxConfig set ComputeType = @computetype,ModifyTime=GETDATE(),OptUserID=@userid where ComputeType != @computetype";
            SqlParameter p = new SqlParameter("@userid", SqlDbType.BigInt, 16);
            p.Value = optUserID;
            SqlParameter p1 = new SqlParameter("@computetype", SqlDbType.Int, 8);
            p1.Value = type;
            DataConfig.QueryNoRecords(BusinessType.DBWrite, sql, p, p1);
            return true;
        }
    }
}
